﻿// JSON C# Class Generator
// http://at-my-window.blogspot.com/?page=json-class-generator

using System;
using Newtonsoft.Json.Linq;
using JsonCSharpClassGenerator;
using TomatoSynchronizer.Store;

namespace TomatoSynchronizer.Entities
{

	public class ProductImage
	{

		public override bool Equals(object obj)
		{
			if(obj is ProductImage)
			{
				ProductImage image = (ProductImage)obj;
				
				string imageSrc = image.name.Substring(image.name.IndexOf("_"));
				imageSrc = imageSrc.Substring(imageSrc.IndexOf("_"));
				
				string imageDest = _name.Substring(_name.IndexOf("_"));
				imageDest = imageDest.Substring(imageDest.IndexOf("_"));
								
				if(image._image == _name && imageSrc == imageDest && image._size == _size)
				{
					return true;
				}
			}
			
			return false;
		}
		
		public ProductImage()
		{
		}

		public ProductImage(string json)
			: this(JObject.Parse(json))
		{
		}

		private JObject __jobject;
		public ProductImage(JObject obj)
		{
			this.__jobject = obj;
		}

		public override int GetHashCode()
		{
			return base.GetHashCode();
		}		

		[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private int _id;
		public int id
		{
			get
			{
				if(_id == null)
					_id = JsonClassHelper.ReadInteger(JsonClassHelper.GetJToken<JValue>(__jobject, "id"));
				return _id;
			}
			set
			{
				_id = value;
			}
		}

		[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private string _image;
		public string image
		{
			get
			{
				if(_image == null)
					_image = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "image"));
				return _image;
			}
			set
			{
				_image = value;
			}
		}

		[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private string _name;
		public string name
		{
			get
			{
				if(_name == null)
					_name = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "name"));
				return _name;
			}
			set
			{
				_name = value;
			}
		}

		[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private string _size;
		public string size
		{
			get
			{
				if(_size == null)
					_size = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "size"));
				return _size;
			}
			set
			{
				_size = value;
			}
		}

		[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private int _default;
		public int Default
		{
			get
			{
				if(_default == null)
					_default = JsonClassHelper.ReadInteger(JsonClassHelper.GetJToken<JValue>(__jobject, "default"));
				return _default;
			}
			set
			{
				_default = value;
			}
		}
	}
}

